<?php
/**
 * 项目：红河移动电路资源管理信息系统
 *
 * 公司：红河移动分公司
 *
 * @author 李朝应
 *
 * E-mail:lichaoying.hh@163.com
 *
 */
class Event_model extends CI_Model {
   function __construct()
    {
        parent::__construct();
    }


    function setUserEvent($event){
     $id="";
     $user= mysql_real_escape_string(trim($this->session->userdata('crms_username_auth')));
     if($user!=""):
      $this->db->where('us_login',$user);
      $this->db->select('us_id,us_name');
      $query = $this->db->get("user");
      foreach ($query->result() as $row){ $id=$row->us_id;$name=$row->us_name;}
      $sql = "INSERT INTO `crms`.`crms_event` (
      `evt_no` ,
      `us_id` ,
      `us_name` ,
      `evt_time` ,
       `event`,
      `us_ip`
       )
      VALUES (
      NULL ,  '{$id}','{$name}', NOW( ) ,'{$event}', '{$_SERVER['REMOTE_ADDR']}'
       );
     ";
     $this->db->query($sql);
     return $this->db->affected_rows();
   endif;
   }
   function getUserEvent($a,$b){
   $login= mysql_real_escape_string(trim($this->session->userdata('crms_username_auth')));
   $this->db->where('us_login',$login);
   $this->db->select("us_id");
   $query = $this->db->get("user");
   foreach ($query->result() as $row){ $id=$row->us_id;}
   $this->db->where('us_id',$id);
   $this->db->order_by("evt_time", "desc");
   $query = $this->db->get('event',$b,$a);//设置一个结果集每页纪录数(limit)和结果集的偏移(offset)
  // SELECT * FROM (`crms_admin_event`) LIMIT 30
   if ($query->num_rows() > 0)
		{
			 return $query; //返回查询结果
        }
 }

 function getUserEventTotal(){
   $login= mysql_real_escape_string(trim($this->session->userdata('crms_username_auth')));
   $this->db->where('us_login',$login);
   $this->db->select("us_id");
   $query = $this->db->get("user");
   foreach ($query->result() as $row){ $id=$row->us_id;}
   $this->db->where('us_id',$id);
   $this->db->order_by("evt_time", "desc");
   $query = $this->db->get('event');
   return $query->num_rows();
 }
}//类定义结束
?>
